import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '../views/Home.vue';
import SmartService from '../views/SmartService';
import SmartOperation from '../views/SmartOperation';
import Enterprise from '../views/Enterprise';
import Vehicle from '../views/Vehicle';
import {EventHub} from '../common/EventHub';

Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/Service',
    name: 'Service',
    component: SmartService
  },
  {
    path: '/SmartOperation',
    name: 'SmartOperation',
    component: SmartOperation
  },
  {
    path: '/Enterprise',
    name: 'Enterprise',
    component: Enterprise
  },
  {
    path: '/Vehicle',
    name: 'Vehicle',
    component: Vehicle
  }
];

const router = new VueRouter({
  // mode: 'history',
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
});

router.beforeEach((to, from, next) => {
  EventHub.$emit('path-change', to.path);
  window.scrollTo(0, 0);
  next();
});

export default router;
